import { defineStore } from "pinia";
const useCounterStore = defineStore("counter", {
  // 相当于 data
  state() {
    return {
      count: 10,
    };
  },
  //   相当于 computed
  getters: {
    double() {
      return this.count * 2;
    },
  },
  //   相当于 methods
  //   注意 pinia 中，没有了mutations
  //   同步异步都写在 actions 中即可
  actions: {
    add() {
      this.count += 10;
    },
    addNum(val) {
      this.count += val;
    },
    addAsync(val) {
      setTimeout(() => {
        this.count += val;
      }, 1000);
    },
  },
});

export default useCounterStore;
